<?php
use app\exception\Myexc;

function dumpr(){
	$num=func_num_args();
	$res=func_get_args();
	foreach($res as $v){
		var_dump($v);
	}
}
function thr($code=0,$data='',$msg=''){ throw (new Myexc($msg, $code,$data));}
function ddr($data=[],$msg='打印输出',$code=202){thr($code,$data,$msg);}
function s($data=[],$msg='成功',$code=200) {	thr($code,$data,$msg);}
function e($msg='失败',$data=[],$code=500) {	thr($code,$data,$msg);}

function apiCha($data,$header)
{
    $salt='123456';
    //查看token
    if (!isset($header["token"]) or $header["token"] != '461f6924bed805723485e08b985049ebbb3a9774') {
        thr($code='505',$data='',$msg='非法获取');
    }
    $app_key = $data['app_key'];
    //查看提交时间
    if ($data['time'] + 60 < time()) {
        thr($code='505',$data='',$msg='非法获取');
    }
    unset($data['app_key']);
    ksort($data);
    $str ='';// http_build_query($data, '', '&', PHP_QUERY_RFC3986);
   // dump($data);
    foreach ($data as $k => $v){
        if(is_array($v)){
            $str .= "&".$k . '=' . toStrCheck($v);
        }else{
            $str .= "&".$k . '=' . $v;
        }
    }
  //  dump($str . '197686741c09329446b110070f88f54d'.$salt,md5($str . '197686741c09329446b110070f88f54d'.$salt));
    if (md5($str . '197686741c09329446b110070f88f54d'.$salt) != $app_key) {
       thr($code='505',$data='',$msg='非法获取');
    }

}

function toStrCheck($obj)
{
    $str='';
    foreach ($obj as $k=>$v){
        if(is_string($v)){
            $str.=$v;
        }
    }
    return $str;
}

